package vip.liux.backend.application.service.pay.dto.demo;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import vip.liux.contracts.shared.enums.pay.PayDemoWithdrawType;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

@Data
public class PayDemoWithdrawCreateDto {

    @NotEmpty(message = "提现标题不能为空")
    private String subject;

    @NotNull(message = "提现金额不能为空")
    @Min(value = 1, message = "提现金额必须大于零")
    private BigDecimal price;

    @NotBlank(message = "收款人账号不能为空")
    private String userAccount;

    private String userName;

    @NotNull(message = "提现方式不能为空")
    private PayDemoWithdrawType type;

    @AssertTrue(message = "收款人姓名")
    public boolean isUserNameValid() {
        // 特殊：支付宝必须填写用户名！！！
        return ObjectUtils.notEqual(type, PayDemoWithdrawType.ALIPAY)
                || ObjectUtils.isNotEmpty(userName);
    }

}
